﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Pg.BioMedics.SDR.Entities;

namespace Pg.BioMedics.SDR.Caching
{
    /// <summary>
    /// Provides an entry point for all caching functionalities 
    /// related with SDR subsystem.
    /// </summary>
    public sealed class SDRCacheContext : BaseCacheContext
    {
        #region Fields

        private static SDRCacheContext instance;

        private DocumentCache documentCache;
        private AnnotationCache annotationCache;
        private TokenCache tokenCache;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates instance of the SDRCacheContext. Thid constructor automatically loads appropriate configuration
        /// from the cachning configuration section embedded in the application configuration file.
        /// </summary>
        private SDRCacheContext()
            : base() { }

        #endregion

        #region Static properties

        /// <summary>
        /// Gets singelton SDRCacheContext instance. This property supports lazy init
        /// </summary>
        public static SDRCacheContext Instance
        {
            get
            {
                if (instance == null)
                    instance = new SDRCacheContext();

                return instance;
            }
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets DocumentCache initialized in this context. This property supports lazy init.
        /// </summary>
        public DocumentCache DocumentCache
        {
            get
            {
                if (this.documentCache == null)
                    this.documentCache = new DocumentCache(CreateCachingStrategy<Document>());

                return this.documentCache;
            }
        }

        /// <summary>
        /// Gets AnnotationCache initialized in this context. This property supports lazy init.
        /// </summary>
        public AnnotationCache AnnotationCache
        {
            get
            {
                if (this.annotationCache == null)
                    this.annotationCache = new AnnotationCache(CreateCachingStrategy<Annotation>());

                return this.annotationCache;
            }
        }

        /// <summary>
        /// Gets TokenCache initialized in this context. This property supports lazy init.
        /// </summary>
        public TokenCache TokenCache
        {
            get
            {
                if (this.tokenCache == null)
                    this.tokenCache = new TokenCache(CreateCachingStrategy<Token>());

                return this.tokenCache;
            }
        }

        #endregion
    }
}
